package butines.game.pathfinder;


public class Node implements Comparable<Node> {

	private int NEXT_ID = 1;
	
	private int id = NEXT_ID++;
	private float x, y;
	private Edges edges;

	public Node(float x, float y) {
		this.x = x;
		this.y = y;
		this.edges = new Edges(this);
	}
	
	public int getId() {
		return id;
	}
	
	public float getX() {
		return x;
	}

	public float getY() {
		return y;
	}
	
	public Edges getEdges() {
		return edges;
	}

//	public void addEdge(Edge edge) {
//		edges.add(edge);
//	}
//	
//	public void removeEdge(Edge edge) {
//		edges.remove(edge);
//	}
//	
//	public void removeEdges() {
//		edges.clear();
//	}
	
	public double distance(Node other) {
		float x = this.x - other.x;
		float y = this.y - other.y;
		return Math.sqrt(x*x + y*y);
	}
	
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("ID: ").append(id).append(" >");
		for (Edge edge: edges) {
			sb.append(' ');
			sb.append(edge.getTo().getId());
		}
		return sb.toString();
	}

	public int compareTo(Node other) {
		return id - other.id;
	}

}